package com.whfc.mach.queue;

import com.whfc.common.constant.QueueConst;
import com.whfc.common.util.JSONUtil;
import com.whfc.mach.dto.iot.MachMsg0x0A;
import com.whfc.mach.entity.AppMachOilLog;
import com.whfc.mach.manager.MachDataManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description:油箱标定数据
 * @author: xugcheng
 * @version: 1.0
 * @date: 2021-01-08 14:59
 */
@Component
@RabbitListener(queues = QueueConst.MACH_MSG_0X0A)
public class MachMsg0x0AQueueListener {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MachDataManager machDataManager;

    @RabbitHandler
    public void process(String msg) {
        try {
            logger.info("mach_msg_0x0A,{}", msg);
            MachMsg0x0A reqMsg = JSONUtil.parseObject(msg, MachMsg0x0A.class);
            if (reqMsg != null) {
                Integer deviceId = reqMsg.getDeviceId();
                AppMachOilLog log = new AppMachOilLog();
                log.setDeviceId(deviceId);
                log.setTime(reqMsg.getTime());
                log.setPressure(reqMsg.getPressure());
                log.setOilPos(reqMsg.getOilPos());
                log.setTemp(reqMsg.getTemp());
                machDataManager.addMachOilLog(log);
            }

        } catch (Exception ex) {
            logger.error("mach_msg_0x0A,消息处理失败", ex);
        }
    }
}
